package com.sangmo.fts.process.inventory.service;

import com.sangmo.boot.framework.common.session.UserSession;
import com.sangmo.boot.framework.plugin.dataview.crud.service.BaseViewService;
import com.sangmo.boot.framework.plugin.dataview.data.IDataViewRepo;
import com.sangmo.fts.common.authority.service.AuthorityEntityService;
import com.sangmo.fts.process.inventory.interfaces.IfOutBoundCreation;
import com.sangmo.fts.process.inventory.model.IfContract;
import com.sangmo.fts.process.inventory.model.IfLadingBill;
import com.sangmo.fts.process.inventory.model.IfLoan;
import com.sangmo.fts.process.inventory.model.IfOutbound;
import com.sangmo.fts.process.inventory.repo.IfOutboundRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Transactional
public class IfOutboundEntityService extends AuthorityEntityService<IfOutbound> {

    @Autowired
    private IfOutboundRepo ifOutboundRepo;

    @Autowired
    private IfLadingBillService ifLadingBillService;

    @Override
    protected IDataViewRepo<IfOutbound> getRepo() {
        return ifOutboundRepo;
    }

    @Override
    protected void onCreate(IfOutbound entity, Object bo) {
        super.onCreate(entity, bo);
        IfOutBoundCreation creation = (IfOutBoundCreation) bo;
        IfLadingBill ladingBill = ifLadingBillService.get(creation.getBillId());
//        IfLoan loan = ifLoanService.get(ifLadingBill.getLoanId());
//        IfContract contract = ifContractService.get(loan.getContractId());
        entity.setPledgee(ladingBill.getPledgee());
        entity.setPledgor(ladingBill.getPledgor());
        entity.setRegulator(ladingBill.getRegulator());
        entity.setConfirmedBy((Long) UserSession.getUserInterface().getId());
    }
}
